package view;

import java.awt.*;
import javax.swing.JComponent;
import model.GpsCoordinate;
import model.GpsReceiver;
import model.Map;
import model.Observer;

public class PositionMarkerViewDecorator extends ViewDecorator implements Observer {
    
    private GpsReceiver gpsReceiver;
    private Map map;
    
    public PositionMarkerViewDecorator(JComponent component, GpsReceiver gpsReceiver, Map map) {
        super(component);
        this.map = map;
        this.gpsReceiver = gpsReceiver;
        this.gpsReceiver.attach(this);
    }

    @Override
    public void update() {
        this.repaint();
    }
    
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D)g;
        
        GpsCoordinate coord = gpsReceiver.getGpsCoordinate();
        
        Point coordPoint = new Point(MapViewUtil.calculateXpixels(map, coord),
                                    MapViewUtil.calculateYpixels(map, coord));
        
        g2d.setStroke(new BasicStroke(2));
        g2d.setColor(Color.red);
        g2d.drawOval(coordPoint.x - 10,
                    coordPoint.y - 10,
                    20,
                    20);
    }
    
}